#!/usr/bin/env python
#coding:utf8

# 导入 smtplib 和 MIMEText
import sys,getpass
import smtplib
from email.mime.text import MIMEText

# 发送邮件函数
def send_mail(to_list, sub,context):
        me = mail_user + "<"+mail_user+"@"+mail_postfix+">"
        msg = MIMEText(context)
        msg['Subject'] = sub
        msg['From'] = me
        msg['To'] = "".join(to_list)
        try:
                send_smtp = smtplib.SMTP()
                send_smtp.connect(mail_host)
                send_smtp.login(mail_user, mail_pass)
                send_smtp.sendmail(me, to_list, msg.as_string())
                send_smtp.close()
                return True
        except Exception, e:
                print str(e)
                return False

# 设置服务器名称、用户名、密码以及邮件后缀
mail_host = "smtp.126.com"
mail_user = "xuefengzang@126.com"
mail_pass = "zang123ZANG"
mail_postfix="126.com"

mailto_list = sys.argv[1]
sub= sys.argv[2]
context=sys.argv[3]

if send_mail(mailto_list,sub,context):
        print "Send mail succed!"
else:
        print "Send mail failed!"
